package com.woniu.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.entity.dto.QueryCarDTO;
import com.woniu.entity.vo.OrderByIdVO;
import com.woniu.entity.vo.QueryCarByIdVO;
import com.woniu.entity.vo.QueryCarVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.entity.dto.QueryCarDTO;
import com.woniu.entity.vo.OrderByIdVO;
import com.woniu.entity.vo.QueryCarByIdVO;
import com.woniu.entity.vo.QueryCarVO;
import com.woniu.entity.vo.UserCarVO;
import com.woniu.pojo.Car;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import org.apache.ibatis.annotations.Select;

/**
* @author Ma.Lei
* @description 针对表【t_car】的数据库操作Mapper
* @createDate 2022-12-16 23:27:39
* @Entity generator.domain.Car
*/
public interface CarMapper extends BaseMapper<Car> {
    List<QueryCarVO> listSearch(@Param("queryCarDTO") QueryCarDTO queryCarDTO);

    @Update("update t_car set `status` = #{status} where `id` = #{id};")
    int disabledCar(String id, Integer status);

    @Select("SELECT t.car_number,t.car_type FROM t_car t WHERE user_id=#{id} and is_deleted = 0; ")
    @ResultType(UserCarVO.class)
    List<UserCarVO> getByNumber(String id);

    @Update("UPDATE t_car t set t.is_deleted = 1 WHERE t.car_number = #{carNumber} and t.user_id = #{id} and is_deleted = 0;")
    Boolean deleteCar(String carNumber, String id);

    @Select("SELECT * from t_car WHERE user_id=#{id} and car_number=#{carNum} and is_deleted = 0 ")
    @ResultType(Car.class)
    Car selectCarByNum(String id, String carNum);

    @Select("SELECT * from t_car t WHERE t.car_number=#{carNum} and t.is_deleted=0")
    @ResultType(Car.class)
    Car getByCarNumber(String carNum);

    @Select("select id,car_number,car_type,order_number,no_pay_order,consume_amount,no_consume_sum,create_time from t_car where is_deleted = 0 and user_id = #{id}")
    List<QueryCarByIdVO> listCarByUserId(String id);

    @Select("select o.id,o.order_code,o.create_time,c.car_number,o.price,o.order_status\n" +
            "\tfrom t_car c,t_order o\n" +
            "\twhere c.id = o.car_id\n" +
            "\tand o.is_deleted = 0\n" +
            "\tand c.id=#{id}")
    List<OrderByIdVO> listOrderByCarId(String id);
    @Select("select id as carId from t_car where car_number = #{carNumber}")
    String getIdByNumber(String carNumber);
}




